/* 
action creator: 用于创建action对象的工厂函数
*/

import { Dispatch } from "redux"

// 增加的action
export const incrementAction = (num: number) => ({ type: "INCREMENT", data: num })
// 减少的action
export const decrementAction = (num: number) => ({ type: "DECREMENT", data: num })

// 异步增加的action
export const incrementAsyncAction = (num: number) => {
  // 返回的回调是redux-thunk帮我们调用的, 且传入了store.dispatch函数
  return (dispatch: Dispatch) => {
    // 执行异步操作
    setTimeout(() => {
      // 完成后再分发同步action
      dispatch(incrementAction(num))
    }, 1000)
  }
}
